import urllib.request
import urllib.parse
import random

proxies = [
    {"http": "103.215.36.27:15818"},
]

proxy = random.choice(proxies)
print(proxy)

url = 'http://www.baidu.com/s?wd=ip'
headers = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36 Edg/129.0.0.0'
}
request = urllib.request.Request(url, headers=headers)
handler = urllib.request.ProxyHandler(proxies=random.choice(proxies))
opener = urllib.request.build_opener(handler)
response = opener.open(request)
html = response.read().decode('utf-8')
# print(html)

with open('ip.html', 'w', encoding="utf-8") as f:
    f.write(html)
